package com.ash.controller.comment;

import com.ash.domain.Comment;
import com.ash.domain.vo.CommentVo;
import com.ash.service.comment.CommentService;
import org.springframework.lang.Nullable;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.Date;
import java.util.List;

/**
 * @author : Chen Chao
 * @encoding : UTF-8
 * @date : 2021/4/5 22:54
 * @file : project06.com.ash.controller.comment.CommentController.java
 * @software : IntelliJ IDEA
 * @since : 1.8
 */
@Controller
public class CommentController {
    @Resource
    CommentService commentService;
    @RequestMapping("/user/comment/add")
    @ResponseBody
    public Integer addComment(Comment comment){
        System.out.println(comment);
        comment.setCreateDate(new Date());
        return commentService.add(comment);
    }
    @RequestMapping("/user/comment/commentList")
    @ResponseBody
    public List<CommentVo> commentList
            (@RequestParam("bid")Integer bid,
             @Nullable @RequestParam("page")Integer page,
             @Nullable@RequestParam("limit")Integer limit,
             @Nullable@RequestParam("order")String order, HttpServletRequest request){
        request.setAttribute("commentCount",commentService.selectDataCount(bid));
        return commentService.selectByBid(bid,page,limit,order);
    }


}
